package com.hr.剑指offer.work1;

/**
 * @author 周恒哲
 * @date 2020/06/17
 **/
public class 面试题66_构建乘积数组 {
    public static int[] constructArr(int[] a) {
        if (a.length==0){
            return new int[0];
        }
        int[] res=new int[a.length];
        res[0]=1;
        int temp=1;
        for (int i = 1; i < a.length; i++) {
            res[i]=res[i-1]*a[i-1];
        }
        for (int i = a.length-2; i >=0 ; i--) {
            temp*=a[i+1];
            res[i]*=temp;
        }
        return res;
    }

    public static void main(String[] args) {

    }
}
